package com.crm.system.service.impl.returnMoney;

import com.crm.common.model.DhPageInfo;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.common.util.CommonUtils;
import com.crm.dao.mapper.returnMoney.BankFlowWhiteListMapper;
import com.crm.model.entity.returnMoney.BankFlowWhiteList;
import com.crm.model.entity.sys.UserAccount;
import com.crm.model.vo.returnMoney.BankFlowWhiteVO;
import com.crm.service.returnMoney.BankFlowWhiteDbService;
import com.crm.system.service.returnMoney.BankFlowWhiteListService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service
public class BankFlowWhiteListServiceImpl implements BankFlowWhiteListService {

    @Autowired
    BankFlowWhiteListMapper bankFlowWhiteListMapper;
    @Autowired
    BankFlowWhiteDbService whiteDbService;

    @Override
    public String addWhiteListName(String whiteListName) {
        if(whiteDbService.queryExistWhiteListName(whiteListName)){
            return ResponseCodeEnum.BANK_FLOW_EXIST_WHITE_LIST_NAME.getResponseCode();
        }
        //当前登陆用户
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();
        BankFlowWhiteList bankFlowWhite = new BankFlowWhiteList();
        bankFlowWhite.setId(CommonUtils.getGUID());
        bankFlowWhite.setCreatePeopleId(userAccount.getAccountId());
        bankFlowWhite.setWhiteListName(whiteListName);
        bankFlowWhite.setCreateTime(new Date());
        if(bankFlowWhiteListMapper.insertSelective(bankFlowWhite)<=0){
            return ResponseCodeEnum.ERROR.getResponseCode();
        }
        return ResponseCodeEnum.OK.getResponseCode();

    }

    @Override
    public DhPageInfo<BankFlowWhiteVO> queryWhiteList(Integer pageIndex, Integer pageSize) {
        if (pageIndex != null && pageSize != null) {
            PageHelper.startPage(pageIndex, pageSize);
        }
        List<BankFlowWhiteVO> bankFlowWhiteVOList = whiteDbService.queryWhiteList();
        PageInfo<BankFlowWhiteVO> pageInfo = new PageInfo<BankFlowWhiteVO>(bankFlowWhiteVOList);
        return new DhPageInfo<BankFlowWhiteVO>(pageInfo, bankFlowWhiteVOList);
    }




}
